<?php

class MyAction extends fvAction {
	function __construct () {
	    parent::__construct(fvSite::$Layoult);
	}
    
    function executeIndex() {
    	$request = fvRequest::getInstance();
    	if (!fvSite::$fvSession->getCustomer()){
			fvDispatcher::getInstance()->redirect(fvSite::$fvConfig->get('dir_web_root'));
		}
        if (!fvRequest::getInstance()->isXmlHttpRequest()) {
            return self::$FV_OK;
        } else {
            return self::$FV_AJAX_CALL;
        }   
    }
    
    function executeSave(){
    	$request = fvRequest::getInstance();
    	if (fvSite::$fvSession->getCustomer()){
    		$Customer = CustomerManager::getInstance()->getByPk(fvSite::$fvSession->getCustomer()->getPk());
    		$n = $request->getRequestParameter("m");
    		$n["active"] = $Customer->active;
    		
    		if (!$Customer->isNew() && (strlen($n['password']) == 0)) {
            	unset($n['password']);
            	unset($n['password1']);
        	}
    		$Customer->updateFromRequest($n);
    		if ($Customer->save(false)){
    			fvSite::$fvSession->set('Success', 'Дані успішно збережено');
    		}
    		else{
    			fvSite::$fvSession->set('Error', $Customer->getValidationResult());
    		}
    		fvDispatcher::getInstance()->redirect(fvSite::$fvConfig->get('dir_web_root') . $request->getRequestParameter('module') . "/".$request->getRequestParameter('operation'));
    	}
    	else{
    		fvDispatcher::getInstance()->redirect(fvSite::$fvConfig->get('dir_web_root'));
    	}
    }
    
	function executeShoworder() {
    	$request = fvRequest::getInstance();
    	if (!fvSite::$fvSession->getCustomer()){
			fvDispatcher::getInstance()->redirect(fvSite::$fvConfig->get('dir_web_root'));
		}
        if (!fvRequest::getInstance()->isXmlHttpRequest()) {
            return self::$FV_OK;
        } else {
            return self::$FV_AJAX_CALL;
        }   
    }
    
}

?>
